package form

import (
	"fmt"
	"net/http"
	"server/global"
	"server/global/e"

	"github.com/astaxie/beego/validation"
	"github.com/gin-gonic/gin"
)

// MarkErrors logs error logs
func MarkErrors(errors []*validation.Error) {
	for _, err := range errors {
		global.LOG.Info(fmt.Sprintf("err:%v, msg: %v", err.Key, err.Message))
	}

	return
}

// BindAndValid binds and validates data
func BindAndValid(c *gin.Context, form interface{}) (int, int) {
	err := c.Bind(form)
	if err != nil {
		return http.StatusBadRequest, e.INVALID_PARAMS
	}

	// valid := validation.Validation{}
	// check, err := valid.Valid(form)
	// if err != nil {
	// 	return http.StatusInternalServerError, e.ERROR
	// }
	// if !check {
	// 	MarkErrors(valid.Errors)
	// 	return http.StatusBadRequest, e.INVALID_PARAMS
	// }

	return http.StatusOK, e.SUCCESS
}
